/**
 * 配置文件
 *   1. 项目配置，优先级低于 .umirc.ts 文件
 *   2. 可以进行插件等的高级配置
 *   3. 可以通过 chainWebpack 配置 webpack
 */
import defaultSettings from './defaultSettings';
import slash from 'slash2';
import { IConfig } from 'umi';

const config: IConfig = {
  // build config
  publicPath: '/static/',
  // publicPath: "http://yourcdn/path/to/static/", // 静态资源在非根目录或 cdn
  // deploy config
  hash: true,
  history: {
    type: 'hash',
  },
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    // ...darkTheme,
    'primary-color': defaultSettings.primaryColor,
  },
  // dynamic load
  dynamicImport: {},
  // webpack config
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (
      context: {
        resourcePath: string;
      },
      _: string,
      localName: string,
    ) => {
      if (
        context.resourcePath.includes('node_modules') ||
        context.resourcePath.includes('ant.design.pro.less') ||
        context.resourcePath.includes('global.less')
      ) {
        return localName;
      }
      const match = context.resourcePath.match(/src(.*)/);
      if (match && match[1]) {
        const antdProPath = match[1].replace('.less', '');
        const arr = slash(antdProPath)
          .split('/')
          .map((a: string) => a.replace(/([A-Z])/g, '-$1'))
          .map((a: string) => a.toLowerCase());
        return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
      }
      return localName;
    },
  },
  // 根路径配置
  base: '/kol',
  manifest: {
    basePath: '/kol',
  },
};

export default config;
